package com.softeem.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.softeem.mapper.BlogMapper;
import com.softeem.pojo.Blog;
import com.softeem.service.BlogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class BlogServiceImpl implements BlogService {

    @Autowired
    BlogMapper blogMapper;


    @Override
    public PageInfo<Blog> getBlogListLimit(int page, int limit, int userId) {
        // 先使用分页插件
        PageHelper.startPage(page, limit,"id desc");
        //调用mapper中的方法
        List<Blog> list = blogMapper.selectByUserId(userId);
        // 把list封装成PageInfo对象
        PageInfo<Blog> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int addBlog(Blog blog) {
        return blogMapper.insertBlog(blog);
    }
}
